$title Open model

$ontext
--------------------------------------------------------------------------------
Small open 2x2 economy with tariffs and export subsidies in the benchmark.
Laurent Cretegny, CoPS, Monash University, Australia, 2003.
--------------------------------------------------------------------------------
$offtext

$set path d:\prof\research\mpsge\mge2gem\examples\mpsge\open

sets
  h                 household                     / hh, fh /
  o                 commodity and sector          / agr, ind /
  f                 primary factor                / lab, cap /;

alias(o,s);

parameters
  sam(*,*)          benchmark social accounting matrix
  factor(f,s)       factor demand
  interm(o,s)       intermediate demand
  demand(o,h)       demand for consumption
  endowdem(f,h)     endowment demand for household
  endow(f,h)        endowment
  govdem(o)         government demand
  export(o)         export (at fob price)
  import(o)         import (at cif price)
  tr_y(s)           tax revenue on output
  tr_w(f,h)         tax revenue on endowment
  tr_e(o)           tax revenue on export
  tr_m(o)           tax revenue on import
  etp(s)            elasticity of transformation in production
  esv(s)            elasticity of substitution in value-added
  esa(s)            elasticity of substitution in aggregate supply
  esc(h)            elasticity of substitution in consumption
  esd(h)            elasticity of substitution in demand
  supply(s)         supply of output
  aggsup(s)         aggregate supply
  cons              aggregate consumption
  govcons           aggregate government consumption
  endowfac(f,h)     endowment for primary factor (gross of tax)
  endowsup(f,h)     endowment supply by household
  t_y(s)            tax rate on output
  t_w(f,h)          tax rate on endowment
  t_e(o)            tax rate on export
  t_m(o)            tax rate on import
  t_y_l(s)          power of tax on output
  t_w_l(f,h)        power of tax on endowment
  t_e_l(o)          power of tax on export
  t_m_l(o)          power of tax on import;

$call gdxxrw i=%path%\open.xls o=%path%\open.gdx index=declare
$gdxin %path%\open.gdx
$load sam = sam
$load etp = etp
$load esv = esv
$load esa = esa
$load esc = esc
$load esd = esd
$gdxin

factor(f,s) = sam(f,s);
interm(o,s) = sam(o,s);
demand(o,h) = sam(o,h);
endowdem(f,h) = sam(f,h);
endow(f,h) = sam(h,f);
govdem(o) = sam(o,"gov");
export(o) = sam(o,"row");
import(o) = sam("row",o);
tr_y(s) = sam("ty",s);
tr_w(f,"hh") = sam("tw_hh",f);
tr_w(f,"fh") = sam("tw_fh",f);
tr_e(o) = -sam(o,"trow");
tr_m(o) = sam("trow",o);
supply(s) = sum(o, interm(o,s)) + sum(f, factor(f,s)) + tr_y(s)
            - (export(s) - tr_e(s));
aggsup(s) = supply(s) + import(s) + tr_m(s);
cons(h) = sum(o, demand(o,h));
govcons = sum(o, govdem(o));
endowfac(f,h) = endow(f,h) + tr_w(f,h) - endowdem(f,h);
endowsup(f,h) = endow(f,h) - endowdem(f,h);
t_y(s) = tr_y(s) / supply(s);
t_w(f,h) = tr_w(f,h) / endowfac(f,h);
t_e(o) = tr_e(o) / export(o);
t_m(o) = tr_m(o) / import(o);
t_y_l(s) = 1 - t_y(s);
t_w_l(f,h) = 1 - t_w(f,h);
t_e_l(o) = 1 - t_e(o);
t_m_l(o) = 1 + t_m(o);

$ontext
$model:open

$sectors:
  y(s)              ! production
  a(s)              ! aggregate supply
  u(h)              ! utility index
  g                 ! government expenditure
  w(f,h)            ! endowment supply index

$commodities:
  p(o)              ! price of output
  pa(o)             ! price of commodity
  pu(h)             ! true cost-of-living index
  pg                ! price of a unit of government output
  pf(f)             ! price of primary factor
  pw(f,h)           ! price of endowment
  pfx               ! real exchange rate

$consumers:
  ra(h)             ! representative agent income
  gov               ! government income

$prod:y(s)          t:etp(s)            s:0.0               s.tl:esv(s)
  o:p(s)            q:supply(s)         p:t_y_l(s)          a:gov     t:t_y(s)
  o:pfx             q:export(s)         p:t_e_l(s)          a:gov     t:t_e(s)
  i:pf(f)           q:factor(f,s)       s.tl:
  i:pa(o)           q:interm(o,s)

$prod:a(s)          s:esa(s)
  o:pa(s)           q:aggsup(s)
  i:p(s)            q:supply(s)
  i:pfx             q:import(s)         p:t_m_l(s)          a:gov     t:t_m(s)

$prod:u(h)          s:esc(h)            h.tl:esd(h)
  o:pu(h)           q:(cons(h)+sum(f,endowdem(f,h)))
  i:pw(f,h)         q:endowdem(f,h)
  i:pa(o)           q:demand(o,h)       h.tl:

$prod:g
  o:pg              q:govcons
  i:pa(o)           q:govdem(o)

$prod:w(f,h)
  o:pf(f)           q:endowfac(f,h)     p:t_w_l(f,h)        a:gov     t:t_w(f,h)
  i:pw(f,h)         q:endowsup(f,h)

$demand:ra(h)
  d:pu(h)           q:(cons(h)+sum(f,endowdem(f,h)))
  e:pw(f,h)         q:endow(f,h)

$demand:gov
  d:pg              q:govcons

$report:
  v:r_supply(s)     o:p(s)              prod:y(s)
  v:r_export(s)     o:pfx               prod:y(s)
  v:r_cons(o,h)     i:pa(o)             prod:u(h)

$offtext
$sysinclude mpsgeset open

* Benchmark replication

open.iterlim = 0;
$include open.gen
solve open using mcp;
abort$(abs(open.objval) gt 1e-7) "*** open does not calibrate ! ***";
open.iterlim = 1000;

* Fixation of a numeraire to allow comparison

pfx.fx = pfx.l;

* Counterfactual : 10% increase in subsidy rate on agricultural export

t_e("agr") = t_e("agr") * 1.1;

$include open.gen
solve open using mcp;

* Results

parameters
  res_com           results by commodity in % change from basis
  res_agg           aggregate results in % change from basis; 

res_com("output",o) = (r_supply.l(o)/supply(o) - 1) * 100;
res_com("export",o) = (r_export.l(o)/export(o) - 1) * 100;
res_com("price",o) = (p.l(o) - 1) * 100;

res_agg("u",h) = (u.l(h) - 1 ) * 100;
res_agg("pu",h) = (pu.l(h) - 1 ) * 100;
res_agg("ra_inc",h) = (ra.l(h)/(cons(h)+sum(f,endowdem(f,h))) - 1 ) * 100;

option decimals = 6;
display res_com, res_agg;
